﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zeus.Thunder.Core;

namespace SharpTrainer.Delegates
{
    delegate T GenericTransformer<T>(T arg);

    class GenUtil
    {
        public static void Transform<T>(T[] values, GenericTransformer<T> t)
        {
            for (int i = 0; i < values.Length; i++)
                values[i] = t(values[i]);
        }
    }

    class GenericDelegateTest : ITestCase
    {
        public void Run()
        {
            int[] values = { 1, 2, 3 };
            GenUtil.Transform(values, Square); // Hook in Square
            foreach (int i in values)
                Console.Write(i + " "); // 1 4 9
        }

        static int Square(int x) { return x * x; }
    }
}
